package timing.ukulele.form.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import timing.ukulele.form.mapper.EntityConfigMapper;
import timing.ukulele.form.persistent.EntityConfig;
import timing.ukulele.persistent.service.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class EntityConfigService extends BaseService<EntityConfigMapper, EntityConfig> {

    final EntityFieldConfigService gatherFieldConfigService;

    public EntityConfigService(EntityFieldConfigService gatherFieldConfigService) {
        this.gatherFieldConfigService = gatherFieldConfigService;
    }

    /**
     * 新增，修改
     *
     * @param holidayConfig
     */
    public void saveData(EntityConfig holidayConfig) {
        if (holidayConfig.getId() == null || holidayConfig.getId() == 0) {
            this.save(holidayConfig);
        } else {
            this.updateById(holidayConfig);
        }
    }

    public IPage<EntityConfig> getPage(Long systemId, int current, int size) {
        Page<EntityConfig> page = new Page<>(current, size);
        LambdaQueryWrapper<EntityConfig> query = new LambdaQueryWrapper<>();
        query.eq(EntityConfig::getSystemId, systemId);
        query.orderByDesc(EntityConfig::getId);
        IPage<EntityConfig> iPage = getBaseMapper().selectPage(page, query);
        return iPage;
    }
}
